﻿using System.ComponentModel;
using System.Windows;

namespace SMF.HowTo.UI.ViewModels
{
    public class ViewModelBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                //Always update the UI using the UI thread
                Application.Current.RootVisual.Dispatcher.BeginInvoke(() => FirePropertyChangedIfNotNull(propertyName));
            }
        }

        private void FirePropertyChangedIfNotNull(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        protected void NotifyUser(string message)
        {
            MessageBox.Show(message);
        }
    }
}